import { useLayoutEffect, useRef } from "react";
import useLatestRef from "./useLatestRef";

export default function useUpdated(hook: () => void, deps: any[] = []) {
  const isMountedRef = useRef(false);

  const hookRef = useLatestRef(hook);
  useLayoutEffect(() => {
    if (!isMountedRef.current) {
      isMountedRef.current = true;
      return;
    }
    hookRef.current();
  }, deps); // eslint-disable-line
}
